package com.erhirent.view;

import com.erhairent.tools.InputTools;

public class ReturnView extends View {

	@Override
	public View showView() {
		String name = null;
		boolean isContinue = true;
		for (; isContinue;) {
			System.out.println("输入您的账号:");

			name = InputTools.next();
			System.out.println("请输入密码 :");
			String Pwd = InputTools.next();
			// 判断用户是否存在
			if (muser.isSame(name, Pwd)) {
				System.out.println(name);
				System.out.println("这是你的账户名?1.是  2.否");

				int c = InputTools.nextInt();
				if (c == 1) {
					isContinue = false;
				} else {
					System.out.println("重新输入:");
				}
			} else {
				System.out.println("密码错误");
			}
		}
		int userID = muser.GetUserId(name);

		boolean istrue = true;

		for (; istrue;) {
			System.out.println("输入您将要还的汽车编号:");
			int carID = InputTools.nextInt();

			if (mcar.isreturn(carID, userID)) {
				// 更新记录删除记录
				if (mcar.deleterecord(carID)) {
					// 更新成功
					System.out.println("还车成功");
					istrue = false;
				} else {
					// 更新失败继续
					System.out.println("还车失败");
				}

			} else {
				System.out.println("此车已还或者非本人借");
				System.out.println("1.继续    2.退出");
				int choose = InputTools.nextInt();
				if (choose != 1) {
					return mView;
				}

			}
		}

		return mView;
	}

}
